package cn.stylefeng.guns.modular.ortherService.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.ortherService.entity.OrtherService;
import cn.stylefeng.guns.modular.ortherService.mapper.OrtherServiceMapper;
import cn.stylefeng.guns.modular.ortherService.model.params.OrtherServiceParam;
import cn.stylefeng.guns.modular.ortherService.model.result.OrtherServiceResult;
import  cn.stylefeng.guns.modular.ortherService.service.OrtherServiceService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * 其他服务 服务实现类
 * </p>
 *
 * @author Dong
 * @since 2023-08-15
 */
@Service
public class OrtherServiceServiceImpl extends ServiceImpl<OrtherServiceMapper, OrtherService> implements OrtherServiceService {

    @Override
    public void add(OrtherServiceParam param){
        OrtherService entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(OrtherServiceParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(OrtherServiceParam param){
        OrtherService oldEntity = getOldEntity(param);
        OrtherService newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public OrtherServiceResult findBySpec(OrtherServiceParam param){
        return null;
    }

    @Override
    public List<OrtherServiceResult> findListBySpec(OrtherServiceParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(OrtherServiceParam param){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(OrtherServiceParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private OrtherService getOldEntity(OrtherServiceParam param) {
        return this.getById(getKey(param));
    }

    private OrtherService getEntity(OrtherServiceParam param) {
        OrtherService entity = new OrtherService();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}
